package generadorDescriptores.forms.edition;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JEditorPane;

import generadorDescriptores.FileInEdition;
import generadorDescriptores.dom.XmlDocument;

import org.w3c.dom.Document;

import com.project.frba.bi.descriptor.DatabaseDescriptor;

public class XMLPanel extends javax.swing.JPanel {

	FileInEdition file;

	/** Creates new form XMLPanel */
	public XMLPanel(FileInEdition file) {
		this.file = file;
		initComponents();
		this.loadFile();
		this.EditorPane.setEditable(false);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		EditorPane = new javax.swing.JEditorPane();

		jScrollPane1.setViewportView(EditorPane);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				layout.createSequentialGroup().addContainerGap().add(
						jScrollPane1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380,
						Short.MAX_VALUE).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				layout.createSequentialGroup().addContainerGap().add(
						jScrollPane1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278,
						Short.MAX_VALUE).addContainerGap()));
	}// </editor-fold>
	//GEN-END:initComponents

	private void loadFile() {
		String doc = XmlDocument.DocumentToString(this.file.getXmlDocument().getDocument());
		this.EditorPane.setText(doc);
	}
	
	public void refresh(XmlDocument xmldoc){
		String doc = XmlDocument.DocumentToString(xmldoc.getDocument());
		this.EditorPane.setText(doc);
		this.EditorPane.repaint();
	}
	
	public JEditorPane getEditorPane(){
		return this.EditorPane;
	}
	
	public void repaintNow(){
		this.EditorPane.repaint();
	}
	
	public String getContentAsString(){
		return this.EditorPane.getText();
	}
	
	
	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JEditorPane EditorPane;
	private javax.swing.JScrollPane jScrollPane1;
	// End of variables declaration//GEN-END:variables

}